import {
    createView
} from './views/create.view';
import {
    validate
} from './validate';
import {
    getCateList
} from './models/getCatelist.model';
import {
    submit
} from './submit';
import {
    modal6
} from '../common/layer';
import {
    upFile
} from './operate';

import {
    uploadImg
} from '../common/uploadImg';



const createBtnHandler = () => {


    modal6('新增', createView());

    $(".modal-form input").iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });

    uploadImg('#picker1', '#thumb'); // 缩略图


    $('#yes').on('ifChecked', function (e) {
       $(".contentShow").hide();
       $(".uploadContent").show();
    });
    $('#no').on('ifChecked', function (e) {
        $(".uploadContent").hide();
        $(".contentShow").show();
    });
    window.upFile=upFile;

    $(document).on('click','#tabbutton li',function(){
        let index = $(this).index();
        if(index == 1){
            $('.baseInfo').removeClass('active').addClass('shownone');
            $('.detail').removeClass('shownone').addClass('active');
            $(this).addClass('hover').siblings('li').removeClass('hover');
        }else{
            $('.detail').removeClass('active').addClass('shownone');
            $('.baseInfo').removeClass('shownone').addClass('active');
            $(this).addClass('hover').siblings('li').removeClass('hover');
        }
    });
    getCateList();


    $('#submitBtn').click(() => {
        let data = {};
        $.each($('#form').serializeArray(), (key, val) => {
            data[val.name] = val.value;
        });
        if (!validate(data)) {
            return;
        }
        submit(GLOBAL_articleAddUrl, data);
    });
};
export {
    createBtnHandler
}